home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include "TimeInterval.h"
- #include "TimeEntry.h"
- #include "TimeGrid.h"
- #include "Utils.h"
- #include <Xm/Form.h>
- #include <Xm/Label.h>
- #include <Xm/SeparatoG.h>
-
- static int count;
- static Arg args[10];
-
- TimeInterval::TimeInterval(const char *n, TimeGrid *grid)
- : VkComponent(n)
- {
- _grid = grid;
-
- _start = 0;
- _length = 0;
- _callback = NULL;
-
- count = 0;
- _baseWidget = XmCreateForm(_grid->getParent(), _name, args, count);
- XtAddEventHandler(_baseWidget, ButtonPressMask, False,
- TimeInterval::button_press, (XtPointer) this);
-
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- _startLabel = XmCreateLabel(_baseWidget, "startLabel", args, count);
- XtManageChild(_startLabel);
- XtAddEventHandler(_startLabel, ButtonPressMask, False,
- TimeInterval::button_press, (XtPointer) this);
-
- count = 0;
- XtSetArg(args[count], XmNbottomAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- _endLabel = XmCreateLabel(_baseWidget, "endLabel", args, count);
- XtManageChild(_endLabel);
- XtAddEventHandler(_endLabel, ButtonPressMask, False,
- TimeInterval::button_press, (XtPointer) this);
-
- count = 0;
- XtSetArg(args[count], XmNtopAttachment, XmATTACH_WIDGET); count++;
- XtSetArg(args[count], XmNtopWidget, _startLabel); count++;
- XtSetArg(args[count], XmNbottomAttachment, XmATTACH_WIDGET); count++;
- XtSetArg(args[count], XmNbottomWidget, _endLabel); count++;
- XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM); count++;
- XtSetArg(args[count], XmNorientation, XmVERTICAL); count++;
- _midSep = XmCreateSeparatorGadget(_baseWidget, "midSep", args, count);
- XtManageChild(_midSep);
-
- count = 0;
- XtSetArg(args[count], XmNheight, &_labelHeight); count++;
- XtGetValues(_startLabel, args, count);
-
- installDestroyHandler();
- }
-
- TimeInterval::~TimeInterval()
- {
- XtRemoveEventHandler(_baseWidget, ButtonPressMask, False,
- TimeInterval::button_press, (XtPointer) this);
- XtRemoveEventHandler(_startLabel, ButtonPressMask, False,
- TimeInterval::button_press, (XtPointer) this);
- XtRemoveEventHandler(_endLabel, ButtonPressMask, False,
- TimeInterval::button_press, (XtPointer) this);
- }
-
- /**********************************************************************/
-
- const char *
- TimeInterval::className()
- {
- return "TimeInterval";
- }
-
- void
- TimeInterval::setTimeInterval(int start, int length)
- {
- Position x, y;
- Dimension width, height;
- char str[256];
- XmString xs;
- Pixel bg;
-
- if (_start != start || _length != length) {
- _start = start;
- _length = length;
- if (_grid->requestIntervalPosition(_start, _length, &x, &y,
- &width, &height)) {
- if (height < 2*_labelHeight) {
- count = 0;
- XtSetArg(args[count], XmNheight, height); count++;
- XtSetValues(_startLabel, args, count);
- } else {
- count = 0;
- XtSetArg(args[count], XmNheight, _labelHeight); count++;
- XtSetValues(_startLabel, args, count);
- }
- count = 0;
- XtSetArg(args[count], XmNx, x); count++;
- XtSetArg(args[count], XmNy, y); count++;
- XtSetArg(args[count], XmNwidth, width); count++;
- XtSetArg(args[count], XmNheight, height); count++;
- XtSetValues(_baseWidget, args, count);
-
- count = 0;
- XtSetArg(args[count], XmNbackground, &bg); count++;
- XtGetValues(_grid->getText()->baseWidget(), args, count);
- count = 0;
- XtSetArg(args[count], XmNbackground, bg); count++;
- XtSetValues(_baseWidget, args, count);
-
- formatShortTime(_start/60, _start%60, str);
- xs = XmStringCreateSimple(str);
- count = 0;
- XtSetArg(args[count], XmNlabelString, xs); count++;
- XtSetArg(args[count], XmNfontList, _grid->getTextFontList()); count++;
- XtSetArg(args[count], XmNbackground, bg); count++;
- XtSetValues(_startLabel, args, count);
-
- formatShortTime((_start+_length)/60, (_start+_length)%60, str);
- xs = XmStringCreateSimple(str);
- count = 0;
- XtSetArg(args[count], XmNlabelString, xs); count++;
- XtSetArg(args[count], XmNfontList, _grid->getTextFontList()); count++;
- XtSetArg(args[count], XmNbackground, bg); count++;
- XtSetValues(_endLabel, args, count);
- }
- }
- if (XtWindow(_baseWidget)) {
- XRaiseWindow(XtDisplay(_baseWidget), XtWindow(_baseWidget));
- }
- }
-
- void
- TimeInterval::setCallback(XtCallbackProc proc, XtPointer client_data)
- {
- _callback = proc;
- _callbackData = client_data;
- }
-
- /**********************************************************************/
-
- void
- TimeInterval::callCallback(TimeIntervalReason reason)
- {
- if (_callback) {
- (*_callback)(_baseWidget, _callbackData, (XtPointer) reason);
- }
- }
-
- /**********************************************************************/
-
- void
- TimeInterval::button_press(Widget, XtPointer client_data, XEvent *event,
- Boolean *)
- {
- TimeInterval *obj = (TimeInterval *) client_data;
-
- if (event->xbutton.button == Button1) {
- obj->callCallback(TI_deselect);
- }
- }
-
-